package downloader.biquge

import downloader.FilePipeline
import downloader.IDownloader
import org.jsoup.Jsoup
import us.codecraft.webmagic.Spider
import java.io.File

class BiqugeDownloader(val url:String) : IDownloader {
    override fun getName(): String {
        val conn = Jsoup.connect(url).timeout(300_000).userAgent("Mozilla/5.0 (Linux; Android 4.4.4; 4G Build/KTU84P)")
        val doc = conn.get()
        val name:String? = doc.select("#maininfo #info h1").first().text()
        return name!!
    }

    override fun download(dir: File) {
        Spider.create(BiqugePageProcessor())
                .addUrl(url)
                .addPipeline(FilePipeline(dir))
                .thread(Runtime.getRuntime().availableProcessors() * 4)
                .run()
    }

}


